from api.utils import Utils


class AiaApi(object):
    # 查询机房列表
    @staticmethod
    def describe_idcs():
        data = {

            "PageNumber": 1,
            "PageSize": 10
        }
        resp = Utils().get_result('DescribeIDCs', data)
        print()

    # 查询规格列表
    @staticmethod
    def describe_spec_list():
        data = {

            "PageNumber": 1,
            "PageSize": 10
        }
        resp = Utils().get_result('DescribeInstanceSpec', data)
        print()

    # 批量查询实例详情信息
    @staticmethod
    def describe_instance_details():
        """
        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        data = {
            "InstanceIDs": ["ins-pkxmwelxdmrysxikanecvlwofkykpfmh"],
            "PageNumber": 1,
            "PageSize": 10
        }
        resp = Utils().get_result('DescribeInstance', data)
        print()

    # 批量创建实例
    @staticmethod
    def create_instance():
        """
        注意事项：

        如果某规格是多开的实例，创建数量必须为多开规格的倍数，否则会创建失败

        单次创建数量最大为 1000

        对于 Arm：数据盘必填且当前只能填一个

        一次只能创建一个规格、一个机房
                """
        """
        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        # 阿里arm 单开
        data = {
            "IDC": "cn-south-foshan-03009",
            "Amount": 1,
            "Spec": "egc-armg2m1a-v1",
            "AutoUseCoupon": True,
            "SystemImageID": "cimg-448a2788f99ccdd218f0aeb001d29777",
            "Namespace": "iaas-test"
        }
        # 阿里arm 双开
        # data = {
        #                 "IDC": "cn-south-foshan-03009",
        #                 "Amount": 2,
        #                 "Spec": "egc-armg2m1a-v2",
        #           "AutoUseCoupon": True,
        #                 "SystemImageID": "cimg-b1470efc9947084fea33c312a184d0ad",
        #             "Namespace": "iaas-test"
        #          }
        # 自建arm 三开
        # data = {
        #                 "IDC": "cn-north-neimeng-3000",
        #                 "Amount": 3,
        #                 "Spec": "egc-armg-v3",
        #                 "SystemImageID": "cimg-7KN90HlxTqK_YS2i343i_30",
        #            }

        # data = {
        #     "IDC": "cn-east-hefei-3009",
        #     "Amount": 1,
        #     "Spec": "egc-x866248rg0a-v1",
        #     "SystemImageID": "os-1dviwvdazib3vls8mbi9bbbof9y2",
        #     "SystemDisk": {"DiskType": "Cloud", "DiskStructure": "Snapshot", "WritingMode": "WriteToLocal"}
        # }
        """
        自建： cimg-7KN90HlxTqK_YS2i343i_30
        阿里： cimg-b1470efc9947084fea33c312a184d0ad
        """
        # 生产环境阿里
        # data = {
        #     "IDC": "cn-east-wuxi-p23",
        #     "Amount": 2,
        #     # "Spec": "egc-armga-v2",
        #     "Spec": "egc-armg2m1a-v2",
        #     "AutoUseCoupon": True,
        #     "SystemImageID": "cimg-b1470efc9947084fea33c312a184d0ad",
        # }

        # 生产环境 自建
        # data = {
        #     "IDC": "cn-north-huhehaote-gr-p0-103",
        #     "Amount": 2,
        #     "Spec": "egc-armg-v2",
        #     "SystemImageID": "cimg-7KN90HlxTqK_YS2i343i_30",
        # }
        resp = Utils().get_result('CreateInstance', data)
        print()

    # 批量重启实例
    @staticmethod
    def reboot_instance():
        """

        """
        """
        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        # 阿里arm 单开
        data = {
            "InstanceIDs": ["cn-south-foshan-03009"],

        }
        resp = Utils().get_result('RebootInstance', data)
        print()

    # 批量释放ARM板卡
    @staticmethod
    def release_serve():
        """

        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        # 阿里arm 单开
        data = {
            "ServerIDs": ["cn-south-foshan-03009"],

        }
        resp = Utils().get_result('ReleaseServer', data)
        print()

    # 批量释放ARM板卡
    @staticmethod
    def reboot_serve():
        """

        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        # 阿里arm 单开
        data = {
            "ServerIDs": ["cn-south-foshan-03009"],

        }
        resp = Utils().get_result('RebootServer', data)
        print()

    # 创建数据镜像
    @staticmethod
    def create_data_image():
        """
        如果您的业务模式为云游戏共享盘模式，请使用以下参数创建空镜像或者增量镜像盘。
        注意：此模式下，制作数据镜像的流程是：
        1. 调用 CreateDataImage
        2. 在实例里写入相应的内容
        3.调用 SaveDataImage 完成镜像的保存，保存成功后会将挂载的镜像盘卸载，下次如果需要制作镜像，则还要把 1、2、3 三个步骤再走一遍。
        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        data = {
            "ImageName": "",
            "AttachInstanceID": "",

        }
        resp = Utils().get_result('CreateDataImage', data)
        print()

    # 保存数据镜像
    @staticmethod
    def save_data_image():
        """
        保存镜像，把镜像上传到实例所在的区域存储。
        注意：镜像上传的时候会先卸载镜像，此接口需要跟。
        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        data = {
            "ImageID": "",
            "UploadToFileStorage": True,

        }
        resp = Utils().get_result('SaveDataImage', data)
        print()

    # 批量分发并部署数据镜像到实例
    @staticmethod
    def deploy_data_image():
        """
        把指定的镜像分发到各个实例所在的机房，并部署到实例上。
        注意事项：

        对于 Arm，部署时，如果实例已挂载了云盘，则自动将该盘卸载并释放（如果该盘是母盘，则仅卸载不释放）

        对于 Arm，部署成功后，会重启实例
        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        data = {
            "ImageID": "",
            "InstanceIDs": [],

        }
        resp = Utils().get_result('DeployDataImage', data)
        print()

    # 批量卸载云硬盘
    @staticmethod
    def detach_disk():
        """
        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        data = {
            "ImageID": "",
            "InstanceIDs": [],

        }
        resp = Utils().get_result('DetachDisk', data)
        print()

    # 批量查询数据镜像信息
    @staticmethod
    def describe_data_image():
        """
        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        data = {
            "ImageID": "",
            "InstanceIDs": [],

        }
        resp = Utils().get_result('DescribeDataImage', data)
        print()


    # 批量部署系统镜像
    @staticmethod
    def deploy_system_image():
        """
        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        data = {
            "ImageID": "",
            "ServerIDs": [],
            "DiskType": "Cloud",
            "DiskStructure": "Snapshot",
            "WritingMode": "WriteToLocal",
            "SyncFromRemote": True,

        }
        resp = Utils().get_result('DeploySystemImage', data)
        print()

    # 批量查询系统镜像信息
    @staticmethod
    def describe_system_image():
        """
        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        data = {
            "ImageID": "os-b9ueb80zhga81badzkzjhy64gbei"

        }
        resp = Utils().get_result('DescribeSystemImage', data)
        print()

    # 查询父任务列表
    @staticmethod
    def describe_task_list():
        """
        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        data = {
            "TaskTypes": ["Storage","Instance","HypervisorOp"] , #Storage：存储任务 Instance：实例任务 HypervisorOp：板卡
            "TaskID": "hyp-89ZBF9Ea9f1CetPjwXjQPyn61"
        }
        resp = Utils().get_result('DescribeTaskList', data)
        print()

    # 查询父任务详情
    @staticmethod
    def describe_task_detail():
        """
        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        data = {
            "TaskType": "" , #Storage：存储任务 Instance：实例任务 HypervisorOp：板卡
            "TaskID": ""
        }
        resp = Utils().get_result('DescribeTaskDetail', data)
        print()

    # 查询订单列表
    @staticmethod
    def describe_order_list():
        """
        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        data = {
            "PageNumber": "" , #Storage：存储任务 Instance：实例任务 HypervisorOp：板卡
            "PageSize": ""

        }
        resp = Utils().get_result('DescribeOrderList', data)
        print()

    # 查询订单详情
    @staticmethod
    def describe_order_detail():
        """
        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        data = {
            "OrderID": "5730"
        }
        resp = Utils().get_result('DescribeOrderDetail', data)
        print()

    # 批量查询板卡 / Arm 板卡信息
    @staticmethod
    def describe_server():
        """
        https://confluence.vrviu.com/pages/viewpage.action?pageId=1654917987
        """
        data = {
            "ServerIDs": ["hyp-oqzmqdsjwfrlhukxtuktyzyza"]
        }
        resp = Utils().get_result('DescribeServer', data)
        print()

if __name__ == '__main__':
    # AiaApi.describe_task_list()
    AiaApi.describe_system_image()
    # AiaApi.create_instance()
    # AiaApi.describe_order_detail()
    # AiaApi.describe_instance_details()
